//
//  SearchViewController.h
//  MyProject
//
//  Created by 石小强 on 2018/4/26.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "UITableView+Empty.h"
#import <Masonry.h>

@implementation UITableView (Empty)

- (void)noDataAddEmptyUIWithImageName:(NSString *)imageName andEmptyText:(NSString *)emptyText
{
    [self haveDataRemoveEmptyUI];
    
    UIImageView * imageV = [[UIImageView alloc] init];
    [self addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).with.mas_offset(48);
        make.size.mas_equalTo(CGSizeMake(192, 107.5));
    }];
    imageV.tag = 88888;
    if (imageName == nil) {
        imageV.backgroundColor = [UIColor redColor];
    }else
        imageV.image = [UIImage imageNamed:imageName];
    
    UILabel * emptyLabel = [[UILabel alloc] init];
    [self addSubview:emptyLabel];
    [emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(imageV.mas_bottom).with.mas_offset(10);
//        make.height.equalTo(@16);
        make.height.equalTo(@40);
    }];
    emptyLabel.tag = 99999;
    emptyLabel.textAlignment = NSTextAlignmentCenter;
    emptyLabel.numberOfLines = 0;
    if (emptyText == nil) {
        emptyLabel.text = @"测试阶段";
    }else{
        emptyLabel.text = emptyText;
    }
    
    emptyLabel.textColor = UIColorFromRGB(0x474C4D);
    emptyLabel.font = [UIFont fontWithName:@"PingFangSC-Light" size:13];
}



- (void)noDataAddEmptyUIWithImageName:(NSString *)imageName andEmptyText:(NSString *)emptyText andTopDistance:(NSInteger)topDistance
{
    [self haveDataRemoveEmptyUI];
    
    UIImageView * imageV = [[UIImageView alloc] init];
    [self addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).with.mas_offset(48 + topDistance);
        make.size.mas_equalTo(CGSizeMake(192, 107.5));
    }];
//    imageV.backgroundColor = [UIColor redColor];
    imageV.tag = 88888;
    if (imageName == nil) {
        imageV.backgroundColor = [UIColor redColor];
    }else
        imageV.image = [UIImage imageNamed:imageName];
    
    UILabel * emptyLabel = [[UILabel alloc] init];
    [self addSubview:emptyLabel];
    [emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(imageV.mas_bottom).with.mas_offset(10);
        //        make.height.equalTo(@16);
        make.height.equalTo(@40);
    }];
    emptyLabel.tag = 99999;
    emptyLabel.textAlignment = NSTextAlignmentCenter;
    emptyLabel.numberOfLines = 0;
    if (emptyText == nil) {
        emptyLabel.text = @"测试阶段";
    }else{
        emptyLabel.text = emptyText;
    }
    
    emptyLabel.textColor = UIColorFromRGB(0x474C4D);
    emptyLabel.font = [UIFont fontWithName:@"PingFangSC-Light" size:13];
}

- (void)haveDataRemoveEmptyUI
{
    for (id view in self.subviews) {
        if ([view isKindOfClass:[UIView class]]) {
            UIView * vieww = (UIView *)view;
            if (vieww.tag == 88888 || vieww.tag == 99999) {
                [vieww removeFromSuperview];
            }
        }
    }
}


@end
